#!/bin/bash

CONFIG_FILE=$PLAY_HOME/configs.txt

# 添加配置信息
add_config() {
    echo "$1 $2" >> "$CONFIG_FILE"
}

# 查询配置信息
query_config() {
    pattern=$1
    awk -v pattern="$pattern" '$1 == pattern { print $2; exit }' "$CONFIG_FILE"
}

# 修改配置信息
modify_config() {
    pattern=$1
    new_value=$2
    sed -i "s@^$pattern.*@$pattern $new_value@" "$CONFIG_FILE"
}

# 主函数
main() {
    case "$1" in
        "add")
            add_config "$2" "$3"
            ;;
        "query")
            result=$(query_config "$2")
            if [[ -z $result ]]; then
                echo "0"
            else
                echo "$result"
            fi
            ;;
        "modify")
            modify_config "$2" "$3"
            ;;
        *)
            echo "无效的命令"
            ;;
    esac
}

# 执行主函数
main "$@"